import java.util.HashMap;

class Solution1 {
    public String minWindow(String s, String t) {
        char[] sNums = s.toCharArray() ;
        int sLen = sNums.length ;
        char[] tNums = t.toCharArray() ;
        int tLen = tNums.length ;
        HashMap<Character,Integer> map = new HashMap<>() ;
        for(char ch : tNums){
            map.put(ch , map.getOrDefault(ch , 0)+1);
        }
        HashMap<Character,Integer> sum = new HashMap<>() ;
        int count = 0 ;
        int index = -1 ;
        int sumLen = Integer.MAX_VALUE ;
        for(int i = 0 ,j=0 ; j < sLen ; j ++){
            char ret = sNums[j];
            if(sum.getOrDefault(ret,0) < map.getOrDefault(ret,0)){
                count ++ ;
            }
            sum.put(ret, sum.getOrDefault(ret,0)+1);

            while(count == tLen){
                if(sumLen > j-i+1){
                    sumLen = j-i+1 ;
                    index = i ;
                }
                char iKey = sNums[i];
                if(map.containsKey(iKey) && sum.get(iKey) <= map.get(iKey)){
                    count -- ;
                }
                sum.put(iKey , sum.getOrDefault(iKey,0)-1);
                i ++ ;
            }
        }
        if(index == -1){
            return "";
        }
        return new String(sNums , index , sumLen);


    }
}